	
	package servlet.grade;
	
	import java.io.IOException;
	import java.util.ArrayList;
	import java.util.List;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import javax.servlet.http.HttpSession;
	import service.GradeManagner;
	import enitys.Grade;
	
	public class GradeInfoByName extends HttpServlet {
	
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		/**
		 * Constructor of the object.
		 */
		public GradeInfoByName() {
			super();
		}
	
	
		/**
		 * The doGet method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to get.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
		public void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
				List<Grade> list =new ArrayList<Grade>();
				HttpSession session = request.getSession();
				GradeManagner manager=GradeManagner.getInstance();
				
				int shenfen=Integer.parseInt(session.getAttribute("shenfen").toString());
				if(request.getParameter("username")==null && shenfen==1){
					
					try {
						list=manager.Allinfo();
						request.setAttribute("grade", list);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}else if(shenfen==0){
					String name=session.getAttribute("username").toString();
					try {
						list= manager.persongrade(name);
						request.setAttribute("grade", list);
						
					} catch (Exception e) {
				
						e.printStackTrace();
					}

				}else{
					String name=session.getAttribute("username").toString();
					try {
						list= manager.persongrade(name);
						request.setAttribute("grade", list);
						
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				if(list.isEmpty()){
					request.setAttribute("message", "无查询结果！");
				}else{
					request.setAttribute("message", "成绩信息如下：");
				}
				if(shenfen==1){
					request.getRequestDispatcher("/jsp/grade/admin_grade.jsp").forward(request, response);
				}else{
					request.getRequestDispatcher("/jsp/grade/s_grade.jsp").forward(request, response);
				}
			
		}
	
		/**
		 * The doPost method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to post.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
		public void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			doGet(request,response);
		}

	}
